package com.lechi.web.controller;

import com.lechi.web.common.core.controller.BaseController;
import com.lechi.web.common.core.domain.AjaxResult;
import com.lechi.web.common.core.page.TableDataInfo;
import com.lechi.web.service.IIotDeviceService;
import com.lechi.web.system.domain.IotGreenDeviceBo;
import com.lechi.web.system.service.IIotGreenDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 大棚Controller
 *
 * @author yangguang
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/iot/greenhouse/device")
public class IotGreenDeviceController extends BaseController {

    @Autowired
    private IIotGreenDeviceService iotGreenDeviceService;

    private IIotDeviceService iotDeviceService;


    /**
     * 查询大棚列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotGreenDeviceBo iotGreenDevice) {
        startPage();
        List<IotGreenDeviceBo> list = iotGreenDeviceService.selectIotGreenDeviceList(iotGreenDevice);
        return getDataTable(list);
    }


    /**
     * 获取大棚详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iotGreenDeviceService.selectIotGreenDeviceById(id));
    }

    /**
     * 新增大棚
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody IotGreenDeviceBo iotGreenDevice) {
        return toAjax(iotGreenDeviceService.insertIotGreenDevice(iotGreenDevice));
    }

    /**
     * 修改大棚
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody IotGreenDeviceBo iotGreenDevice) {
        return toAjax(iotGreenDeviceService.updateIotGreenDevice(iotGreenDevice));
    }

    /**
     * 删除大棚
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iotGreenDeviceService.deleteIotGreenDeviceByIds(ids));
    }
}
